package entities_testCase;

import junit.framework.TestCase;
import smallTools.SimpleTime;
import entities.Section;

public class SectionTest extends TestCase {

	private String sectionId1;
	private String sectionId2;
	private int size1;
	private int size2;
	private int duration1;
	private int duration2;
	private String staffId1;
	private String staffId2;

	public void setUp() {
		sectionId1 = "sectionId1";
		sectionId2 = "sectionId2";
		size1 = 60;
		size2 = 50;
		duration1 = 2;
		duration2 = 3;
		staffId1 = "staffId1";
		staffId2 = "staffId2";

		new Section(sectionId1, size1, duration1, staffId1);
		new Section(sectionId2, size2, duration2, staffId2);
	}

	public void tearDown() {
		Section.clear();
	}

	// Test case 1: insert twice (for branch coverage)
	public void test_insertTwice() {
		new Section(sectionId1, size1, duration1, staffId1);
		assertEquals(2, Section.getSectionIdList().length);
	}

	// Test case 2: basic setters and getters
	public void test_basic_setters_getters() {
		Section s0 = Section.getSectionById(sectionId1);
		assertEquals(sectionId1, s0.getSectionId());
		assertEquals(size1, s0.getSectionSize());
		assertEquals(duration1, s0.getSectionDuration());
		assertEquals(staffId1, s0.getSectionStaffId());

		assertEquals(null, Section.getSectionById("dummy"));
	}

	// Test case 3: setSectionRoom() and getSectionRoomId()
	public void test_setSectionRoom_getSectionRoomId() {
		Section s0 = Section.getSectionById(sectionId1);
		String testRoomId = "rmId";
		s0.setSectionRoom(testRoomId);
		assertEquals(testRoomId, s0.getSectionRoomId());
	}

	// Test case 4: setSectionStartTime() and getSectionStartTime()
	public void test_setSectionStartTime_getSectionStartTime() {
		Section s0 = Section.getSectionById(sectionId1);
		assertEquals(null, s0.getSectionStartTime());
		SimpleTime testStartTime = new SimpleTime("Mon", 11, 30);
		s0.setSectionStartTime(testStartTime);
		assertEquals("Mon 11:30", s0.getSectionStartTime().toString());
	}

	// Test case 5: getTotalSectionSize(), getSectionIdList(),
	// getSectionByIndex()
	public void test_getTotalSectionSize_getSectionIdList_getSectionByIndex() {
		assertEquals(2, Section.getTotalSectionSize());

		String[] sections = Section.getSectionIdList();
		assertEquals(sectionId1, sections[0]);
		assertEquals(sectionId2, sections[1]);
	}

	// Test case 6: toString()
	public void test_toString() {
		Section s0 = Section.getSectionById(sectionId1);
		SimpleTime testStartTime = new SimpleTime("Mon", 11, 30);
		s0.setSectionStartTime(testStartTime);
		String testRoomId = "rmId";
		s0.setSectionRoom(testRoomId);
		String result0 = "sectionId1 60 Mon 11:30 Mon 13:30 rmId staffId1";
		assertEquals(result0, s0.toString());

		Section s1 = Section.getSectionById(sectionId2);
		String result1 = "sectionId2 50 Unspecified Time Slot and Room staffId2";
		assertEquals(result1, s1.toString());
	}

	// Test case 7: empty and only one element (for loop coverage)
	public void test_emptyAndOnlyOneElement() {
		Section.clear();
		assertEquals(0, Section.getSectionIdList().length);
		new Section(sectionId1, size1, duration1, staffId1);
		assertEquals(1, Section.getSectionIdList().length);
	}
}
